package com.systop.supervise.controller;
import com.systop.common.pojo.course_library;
import com.systop.common.util.ResponseResult;
import com.systop.supervise.service.CourselibraryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
public class CourselibraryController {
    @Autowired
    private CourselibraryService courselibraryService;
    @RequestMapping(value = "/updataCourse_library", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult updataCourse_library(@RequestParam(value = "course_id") String course_id, @RequestParam(value = "course_name") String course_name, @RequestParam(value = "college_name") String college_name, @RequestParam(value = "performance_rule_id") String performance_rule_id, @RequestParam(value = "class_hour") String class_hour, @RequestParam(value = "credit") String credit, @RequestParam(value = "course_group_name") String course_group_name, @RequestParam(value = "introduction") String introduction, @RequestParam(value = "remark") String remark) {
        course_library c = new course_library();
        System.out.println(course_id);
        System.out.println(Integer.parseInt(course_id));
        c.setCourse_id(Integer.parseInt(course_id));
        c.setCourse_name(course_name);
        c.setCollege_name(college_name);
        int performance_rule_id1 = Integer.parseInt(performance_rule_id);
        c.setPerformance_rule_id(performance_rule_id1);
        c.setClass_hour(class_hour);
        BigDecimal b = new BigDecimal(credit);
        c.setCredit(b);
        c.setCourse_group_name(course_group_name);
        c.setIntroduction(introduction);
        c.setRemark(remark);
        int i = courselibraryService.updataCourse_library(c);
        if (i == 0) {
            return ResponseResult.build(500, "修改失败");
        } else {
            return ResponseResult.build(200, "修改成功", c);
        }
    }

    //添加信息
    @RequestMapping(value = "/insertCourse_library", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult insertCourse_library(@RequestParam(value = "course_id") String course_id, @RequestParam(value = "course_name") String course_name, @RequestParam(value = "college_name") String college_name, @RequestParam(value = "performance_rule_id") String performance_rule_id, @RequestParam(value = "class_hour") String class_hour, @RequestParam(value = "credit") String credit, @RequestParam(value = "course_group_name") String course_group_name, @RequestParam(value = "introduction") String introduction, @RequestParam(value = "remark") String remark) {
        course_library c = new course_library();
        System.out.println(course_id);
        System.out.println(Integer.parseInt(course_id));
        c.setCourse_id(Integer.parseInt(course_id));
        c.setCourse_name(course_name);
        c.setCollege_name(college_name);
        int performance_rule_id1 = Integer.parseInt(performance_rule_id);
        c.setPerformance_rule_id(performance_rule_id1);
        c.setClass_hour(class_hour);
        BigDecimal b = new BigDecimal(credit);
        c.setCredit(b);
        c.setCourse_group_name(course_group_name);
        c.setIntroduction(introduction);
        c.setRemark(remark);
        int i = courselibraryService.insertCourse_library(c);
        if (i == 0) {
            return ResponseResult.build(500, "失败");
        } else {
            return ResponseResult.build(200, "添加成功", i);
        }
    }

    //查看全部
    @RequestMapping(value = "/sourse_libraryList", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult sourse_libraryList() {
        List<course_library> list = courselibraryService.sourse_libraryList();

        if (list == null) {
            return ResponseResult.build(500, "失败");
        } else {
            return ResponseResult.build(200, "查看成功", list);

        }
    }

    //通过id查询
    @RequestMapping(value = "/course_libraryIdlist",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult course_libraryIdlist(@RequestParam(value = "course_id") int course_id){
        List<course_library> list= courselibraryService.course_libraryIdlist(course_id);
        if (list == null){
            return  ResponseResult.build(500,"失败");
        }else{
            return  ResponseResult.build(200,"查询成功",list);
        }
    }

    //删除信息
    @RequestMapping(value = "/deleteCourse_library",method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult deleteCourse_library(@RequestParam(value = "course_id")  String course_id){
        int course_id1 = Integer.parseInt(course_id);
        int i = courselibraryService.deleteCourse_library(course_id1);
        if (i == 0){
            return  ResponseResult.build(500,"失败");
        }else{
            return  ResponseResult.build(200,"成功",i);
        }
    }

}